package com.ktgj.flight.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.flight.domain.FlightOrderProduct;
import com.ktgj.flight.service.IFlightOrderProductService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 订单通用产品-保险，优惠劵等Controller
 * 
 * @author ruoyi
 * @date 2021-10-26
 */
@ControllerAdvice
@RestController
@RequestMapping("/product")
public class FlightOrderProductController extends BaseController
{
    @Autowired
    private IFlightOrderProductService flightOrderProductService;

    /**
     * 查询订单通用产品-保险，优惠劵等列表
     */
    @PreAuthorize(hasPermi = "flight:product:list")
    @GetMapping("/list")
    public TableDataInfo list(FlightOrderProduct flightOrderProduct)
    {
        startPage();
        List<FlightOrderProduct> list = flightOrderProductService.selectFlightOrderProductList(flightOrderProduct);
        return getDataTable(list);
    }

    /**
     * 导出订单通用产品-保险，优惠劵等列表
     */
    @PreAuthorize(hasPermi = "flight:product:export")
    @Log(title = "订单通用产品-保险，优惠劵等", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlightOrderProduct flightOrderProduct) throws IOException
    {
        List<FlightOrderProduct> list = flightOrderProductService.selectFlightOrderProductList(flightOrderProduct);
        ExcelUtil<FlightOrderProduct> util = new ExcelUtil<FlightOrderProduct>(FlightOrderProduct.class);
        util.exportExcel(response, list, "订单通用产品-保险，优惠劵等数据");
    }

    /**
     * 获取订单通用产品-保险，优惠劵等详细信息
     */
    @PreAuthorize(hasPermi = "flight:product:query")
    @GetMapping(value = "/{orderProductId}")
    public AjaxResult getInfo(@PathVariable("orderProductId") Long orderProductId)
    {
        return AjaxResult.success(flightOrderProductService.selectFlightOrderProductById(orderProductId));
    }

    /**
     * 新增订单通用产品-保险，优惠劵等
     */
    @PreAuthorize(hasPermi = "flight:product:add")
    @Log(title = "订单通用产品-保险，优惠劵等", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlightOrderProduct flightOrderProduct)
    {
        return toAjax(flightOrderProductService.insertFlightOrderProduct(flightOrderProduct));
    }

    /**
     * 修改订单通用产品-保险，优惠劵等
     */
    @PreAuthorize(hasPermi = "flight:product:edit")
    @Log(title = "订单通用产品-保险，优惠劵等", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlightOrderProduct flightOrderProduct)
    {
        return toAjax(flightOrderProductService.updateFlightOrderProduct(flightOrderProduct));
    }

    /**
     * 删除订单通用产品-保险，优惠劵等
     */
    @PreAuthorize(hasPermi = "flight:product:remove")
    @Log(title = "订单通用产品-保险，优惠劵等", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderProductIds}")
    public AjaxResult remove(@PathVariable Long[] orderProductIds)
    {
        return toAjax(flightOrderProductService.deleteFlightOrderProductByIds(orderProductIds));
    }
}
